package jym.tan.movielibrary.configuration;

import jym.tan.movielibrary.constant.BeanConstant;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;

public class ConfigurationManager {
	
	private static ConfigurationManager configurationManager;
	private static ApplicationContext applicationContext;
	
	private ConfigurationManager() {
		
	}
	
	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	
	public static void setApplicationContext(ApplicationContext applicationContext) {
		ConfigurationManager.applicationContext = applicationContext;
	}
	
	public Configuration getConfiguration() {
		return (Configuration) getBeanFactory().getBean(BeanConstant.CONFIGURATION);
	}

	public BeanFactory getBeanFactory() {
		return (BeanFactory) applicationContext;
	}
	
	public static final synchronized ConfigurationManager getInstance() {
		if(configurationManager == null) {
			configurationManager = new ConfigurationManager();
		}
		return configurationManager;
	}
}
